<?php get_header(); ?>
<!-- 文章页面开始 -->
<div id="single_main" class="main am-margin-top-sm am-margin-bottom-xl">
    <div class="am-g am-g-fixed single am-padding-vertical-xl">
        <div class="am-u-md-8">
            <h1 class="single_title am-margin-0 yu-text-normal am-text-xl"><?php single_post_title() ?></h1>
            <div class="signle_cont">
                <?php if ( have_posts() ) : ?>
                  <?php while ( have_posts() ) : the_post(); ?>
                    <div class="single_info am-fl am-margin-vertical-sm">
                        <span class="am-padding-right-sm"><i class="am-text-primary am-padding-right-xs am-icon-user"></i><?php the_author(); ?></span>
                        <span class="am-padding-right-sm"><i class="am-text-primary am-padding-right-xs am-icon-calendar"></i><?php the_date('Y-m-d'); ?></span>
                        <span class="am-padding-right-sm"><i class="am-text-primary am-padding-right-xs am-icon-eye"></i><?php get_post_views($post -> ID); ?>次</span>
                    </div>
                    <div class="share_box am-fr am-margin-vertical-xs" id="share_box">
                        <!--通用频道页首代码结束-->
                        <div class="bdsharebuttonbox">
                            <a class="bds_weixin" data-cmd="weixin"></a>
                            <a class="bds_tsina" data-cmd="tsina"></a>
                            <a class="bds_sqq" data-cmd="sqq"></a>
                        </div>
                        <script>
                          window._bd_share_config = {
                            common : {
                              //此处放置通用设置
                              bdText :'<?php single_post_title() ?>',
                              bdDesc : '<?php bloginfo(‘description’); ?>', 
                              bdUrl : window.location.href,   
                              bdPic : '<?php echo get_template_directory_uri(); ?>/assets/imgs/logo_top.png'
                            },
                            share : [{
                              bdSize : 24,
                              'bdCustomStyle':'<?php echo get_template_directory_uri(); ?>/assets/css/share_style.css'
                            }]
                          }
                          with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
                        </script>
                    </div>
                    <div class="am-cf"></div>
                    <?php the_content(); ?>
                  <?php endwhile; ?>
                <?php endif; ?>
            </div>
            <!-- 分页 -->
            <ul class="am-pagination am-padding-vertical-lg">
              <li class="am-pagination-prev"><?php previous_post_link('%link', '<span class="am-icon-angle-left am-padding-right-xs"></span>上一篇', false); ?></li>
              <li class="am-pagination-next"><?php next_post_link('%link', '下一篇<span class="am-icon-angle-right am-padding-left-xs"></span>', false); ?></li>
            </ul>
        </div>
        <div class="am-u-md-4 ">
            <div class="sider_bar am-padding am-margin-bottom-sm">
                <div class="tilte am-text-lg">最新文章</div>
                <ul class="news_list am-padding-left">
                    <?php
                        $args = array( 'posts_per_page' =>5, 'order'=> 'ASC', 'orderby' => 'title' );
                        $rand_posts = get_posts( $args );
                        foreach( $rand_posts as $post ) : ?>
                        <li class="am-margin-bottom-sm">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="am-badge am-round am-fr"><?php the_date('Y-m-d'); ?></span>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>
            <div class="sider_bar am-padding am-margin-bottom-sm">
                <div class="tilte am-text-lg">相关文章</div>
                <ul class="rand_list">
                    <?php
                    global $post;
                    $cats = wp_get_post_categories($post->ID);
                    if ($cats) {
                        $args = array(
                              'category__in' => array( $cats[0] ),
                              'post__not_in' => array( $post->ID ),
                              'showposts' => 5,
                              'caller_get_posts' => 1
                          );
                      query_posts($args);
                      if (have_posts()) {
                        while (have_posts()) {
                            the_post(); update_post_caches($posts); ?>
                            <li class="am-margin-bottom-sm">
                                <a href="<?php the_permalink(); ?>">
                                    <?php
                                        if(has_post_thumbnail()){ 
                                            echo the_post_thumbnail('post-thumbnail-464-200');
                                        } else {
                                            echo '<img src="'.get_template_directory_uri().'/assets/imgs/tem_logo.jpg">';
                                        }
                                    ?>
                                </a>
                                <h4 class="art_title am-text-sm yu-text-normal am-text-center am-margin-0"><?php the_title(); ?></h4>
                            </li>
                    <?php
                        }
                      } 
                      else {
                        echo '<li>* 暂无相关文章</li>';
                      }
                      wp_reset_query(); 
                    }
                    else {
                      echo '<li>* 暂无相关文章</li>';
                    }
                    ?>
                </ul>
            </div>
        </div>
        <div class="am-cf"></div>
    </div>
</div>
<!-- 文章页面结束 -->
<?php get_footer(); ?>


